package ide.ccf.ccproject.wizards.pages;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.FileTime;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import ide.ccf.ccproject.common.Utils;
import ide.ccf.ccproject.data.FileInfo;
import ide.ccf.ccproject.data.GenerateFilelist;
import ide.ccf.ccproject.data.SetDesktop;
import ide.ccf.ccproject.data.SetInstall;
import ide.ccf.ccproject.data.TvContentProvider;
import ide.ccf.ccproject.data.SetControlXml;
import ide.ccf.ccproject.templateengine.SwitchConsoleProjectData;
import ide.ccf.ccproject.translate.Message;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.TableEditor;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;


public class ExportSetInfoWizardPage extends WizardPage {
	public static Table table, table2, table3, table4;
	public static Label tips, tips2, tips3, tips4;
	//public static  List<FileInfo> list = new ArrayList<FileInfo>(); 
	public static int count;
	public static boolean bXml = false;
	public static boolean bInstall = false;
	public static boolean bFilelist = false; 
	public ExportSetInfoWizardPage(String pageName) {
		super(pageName);
		setTitle(pageName);
		setDescription(Message.ExportCpkWizard_12);
		setPageComplete(bXml && bInstall && bFilelist);
		count = 0;
	}

	public void createControl(Composite parent) {	
		Composite workArea = new Composite(parent, SWT.CLOSE);
		setControl(workArea);
		GridLayout layout = new GridLayout();
		layout.numColumns = 1;
		layout.verticalSpacing = 1;
		workArea.setLayout(layout);
		workArea.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
		
        String filePath = ExportSetInfoWizardPage.class.getProtectionDomain().getCodeSource().getLocation().toString();
		//System.out.println("{"+filePath +"}");
		//得到{file:/home/chengzhibin/git/IDECCfEclipse/CCFEclipseIntergration/ide.ccf.ccproject/}数据，
		//需要进行截取转化
		String fPath[] = filePath.split(":");
        final String path = fPath[1] + "/icons/yes.png";  
        final Image createdImage =new Image(Display.getCurrent(), path);  
        
		Group g1 = new Group(workArea, SWT.NULL);
		GridData gd1 = new GridData(GridData.FILL_BOTH);
		g1.setLayoutData(gd1);
		GridLayout _layout = new GridLayout(3,false);
		_layout.horizontalSpacing = 5;
		g1.setLayout(_layout);
		g1.setText("1.设置control.xml文件");
		
		table = new Table(g1, SWT.FULL_SELECTION | SWT.MULTI);
		table.setHeaderVisible(false);
		table.setLinesVisible(false);
		table.setTouchEnabled(false);

		// 创建表头的字符串数组  
		TableColumn newColumnTableColumn = new TableColumn(table, SWT.NONE);
        newColumnTableColumn.setWidth(100);
        newColumnTableColumn.setText(Message.ExportSetInfoWizardPage_5);

        TableColumn newColumnTableColumn_1 = new TableColumn(table, SWT.NONE);
        newColumnTableColumn_1.setWidth(290);
        newColumnTableColumn_1.setText(Message.ExportSetInfoWizardPage_6);
       
        TableColumn newColumnTableColumn_２ = new TableColumn(table, SWT.NONE);
        newColumnTableColumn_２.setWidth(150);
        newColumnTableColumn_２.setText(Message.ExportSetInfoWizardPage_7);
               
        TableItem item = new TableItem(table, SWT.NONE);
        item.setText(new String[]{"", "", ""});
        item.setBackground(new Color(null, 230, 230, 230));
       
        table.addMouseListener(new MouseAdapter() {  
            public void mouseDown(MouseEvent e) {  
                if (e.button == 3) {  
                    Menu menu = new Menu(table);  
                    table.setMenu(menu);  
                    MenuItem item = new MenuItem(menu, SWT.PUSH);  
                    item.setText("定位"); 
                    item.addListener(SWT.Selection, new Listener() {  
                        public void handleEvent(Event event) {  
                            TableItem item1 = (TableItem) table  
                                    .getSelection()[0];  
                            Table parent = item1.getParent();  
                            if (parent != null) {  
                                
                                String pathSFolder = ExportSelectFolderWizardPage.sfoldernamePath_cache;
                				String pathCPK = pathSFolder +"/CPK/";
                				try {
									Runtime.getRuntime().exec("gnome-open " + pathCPK);
								} catch (IOException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								} 
                        }}});  
                    MenuItem item2 = new MenuItem(menu, SWT.PUSH);  
                    item2.setText("删除"); 
                    //item.setImage(createdImage);
                    item2.addListener(SWT.Selection, new Listener() {  
                        public void handleEvent(Event event) {  
                            TableItem item1 = (TableItem) table  
                                    .getSelection()[0];  
                            Table parent = item1.getParent();  
                            if (parent != null) {       
                                String pathSFolder = ExportSelectFolderWizardPage.sfoldernamePath_cache;
                				String pathCPK = pathSFolder +"/CPK/";
                				TableItem item = table.getItem(table.getSelectionIndex());
                				String fileName =  item.getText().trim();
                			    File myFile = new File(pathCPK + fileName);
                			    if(myFile.exists())
                			    {               
                				    myFile.delete();
                				    table.remove(table.getSelectionIndices());  
                                    TableItem it = new TableItem(table, SWT.NONE);
                                    it.setText(new String[]{"", "", ""});
                                    it.setBackground(new Color(null, 230, 230, 230));
            				    	bXml = false;
            				    	setPageComplete(false);
            				    	updateTips(tips, false);
                			    }  
                        }}});  
                }  
            }  
        });  
        
        table.addListener(SWT.MeasureItem, new Listener() {
            public void handleEvent(Event event) {
                event.height = 28;
            }
        });
        
        tips = new Label(g1, SWT.NULL);
        tips.setImage(createdImage);
        tips.setVisible(false);
        
        Button button = new Button(g1, SWT.NULL);
        button.setText("设置");
        GridData _gd = new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1);
        _gd.widthHint = 80;
        _gd.heightHint = 35;
	    button.setLayoutData(_gd);
	    button.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				String pathSFolder = ExportSelectFolderWizardPage.sfoldernamePath_cache;	
				String pathCPK = pathSFolder +"/CPK/";
				String file = pathCPK +"control.xml";
				SetControlXml SC = new SetControlXml(Display.getCurrent().getActiveShell());
				SC.open(file);
				
				if(Utils.isExistFile(file) && SC.flag == 1)
				{
					System.out.println(pathCPK);
					//获取文件创建的时间
					File fs  =  new File(file); 
					long modify = fs.lastModified();
					FileInfo f = new FileInfo("control.xml", pathCPK, new  Timestamp(modify).toString());
					//list.add(f);
					 //设置表格数据  
					int n = table.getItemCount();
					for(int i = 0; i < n; ++i)
					{
						 TableItem item = table.getItem(i);
						 if(item.getText().trim().equals("control.xml") ||item.getText().trim().isEmpty())
						 {
							 item.setText(f.toArray()); 
				             SC.flag = 0;
				             break;
						 }
					}   
					bXml = true;
					updateTips(tips, true);
					setPageComplete(bXml && bFilelist && bInstall);
				}
			}});
	    
      
  
        Group g2 = new Group(workArea, SWT.NULL);
		GridData gd2 = new GridData(GridData.FILL_BOTH);
		g2.setLayoutData(gd2);
		GridLayout _layout2 = new GridLayout(3,false);
		_layout2.horizontalSpacing = 5;
		g2.setLayout(_layout2);
		g2.setText("2.设置install文件");
			
		table2 = new Table(g2, SWT.FULL_SELECTION | SWT.MULTI);
		table2.setHeaderVisible(false);
		table2.setLinesVisible(false);
		
		table2.addMouseListener(new MouseAdapter() {  
            public void mouseDown(MouseEvent e) {  
                if (e.button == 3) {  
                    Menu menu = new Menu(table2);  
                    table2.setMenu(menu);
                    MenuItem item = new MenuItem(menu, SWT.PUSH);  
                    item.setText("定位"); 
                    item.addListener(SWT.Selection, new Listener() {  
                        public void handleEvent(Event event) {  
                            TableItem item1 = (TableItem) table2  
                                    .getSelection()[0];  
                            Table parent = item1.getParent();  
                            if (parent != null) {  
                                
                                String pathSFolder = ExportSelectFolderWizardPage.sfoldernamePath_cache;
                				String pathCPK = pathSFolder +"/CPK/";
                				try {
									Runtime.getRuntime().exec("gnome-open " + pathCPK);
								} catch (IOException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								} 
                        }}});  
                    MenuItem item2 = new MenuItem(menu, SWT.PUSH);  
                    item2.setText("删除"); 
                    item2.addListener(SWT.Selection, new Listener() {  
                        public void handleEvent(Event event) {  
                            TableItem item1 = (TableItem) table2  
                                    .getSelection()[0];  
                            Table parent = item1.getParent();  
                            if (parent != null) {                                 
                                String pathSFolder = ExportSelectFolderWizardPage.sfoldernamePath_cache;
                				String pathCPK = pathSFolder +"/CPK/";
                				TableItem item = table2.getItem(table2.getSelectionIndex());
                				String fileName =  item.getText().trim();
                			    File myFile = new File(pathCPK + fileName);
                			    if(myFile.exists())
                			    {               
                				    myFile.delete();
                				    table2.remove(table2.getSelectionIndices());  
                                    TableItem it = new TableItem(table2, SWT.NONE);
                                    it.setText(new String[]{"", "", ""});
                                    it.setBackground(new Color(null, 230, 230, 230));
                 			    	bInstall = false;
                 			    	updateTips(tips2, false);
            				    	setPageComplete(false);
                			    }  
                        }}});  
                }  
            }  
        });    
		
		table2.addListener(SWT.MeasureItem, new Listener() {
            public void handleEvent(Event event) {
                event.height = 28;
            }
        });
		
		// 创建表头的字符串数组  
		newColumnTableColumn = new TableColumn(table2, SWT.NONE);
        newColumnTableColumn.setWidth(100);
        newColumnTableColumn.setText(Message.ExportSetInfoWizardPage_5);

        newColumnTableColumn_1 = new TableColumn(table2, SWT.NONE);
        newColumnTableColumn_1.setWidth(290);
        newColumnTableColumn_1.setText(Message.ExportSetInfoWizardPage_6);
       
        newColumnTableColumn_２ = new TableColumn(table2, SWT.NONE);
        newColumnTableColumn_２.setWidth(150);
        newColumnTableColumn_２.setText(Message.ExportSetInfoWizardPage_7);

        TableItem item2 = new TableItem(table2, SWT.NONE);
        item2.setText(new String[]{"", "", ""});
        item2.setBackground(new Color(null, 230, 230, 230));
        
        tips2 = new Label(g2, SWT.NULL);
        tips2.setImage(createdImage);
        tips2.setVisible(false);
        
        Button button2 = new Button(g2, SWT.NULL);
        button2.setText("设置");
        GridData _gd2 = new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1);
        _gd2.widthHint = 80;
        _gd2.heightHint = 35;
	    button2.setLayoutData(_gd2);
	    button2.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				String pathSFolder = ExportSelectFolderWizardPage.sfoldernamePath_cache;
				String pathCPK = pathSFolder +"/CPK/";
					SetInstall SI = new SetInstall(Display.getCurrent().getActiveShell(),  table);
					SI.open(pathCPK);
					String file = pathCPK + SI.getScriptName();	
					if(Utils.isExistFile(file) && SI.flag == 1)
					{
						//获取文件创建的时间
						File fs  =  new File(file); 
						long modify = fs.lastModified();
						FileInfo f = new FileInfo(SI.getScriptName(), pathCPK, new  Timestamp(modify).toString());
						//list.add(f);
						 //设置表格数据  
						int n = table2.getItemCount();
						for(int i = 0; i < n; ++i)
						{
							 TableItem item = table2.getItem(i);
							 if(item.getText().trim().equals(SI.getScriptName()) || item.getText().trim().isEmpty())
							 {
								 item.setText(f.toArray()); 
					             SI.flag = 0;
					             break;
							 }
						}   
						bInstall = true;
						updateTips(tips2, true);
						setPageComplete(bXml && bFilelist && bInstall);
					}
			}});
        
        
        Group g3 = new Group(workArea, SWT.NULL);
		GridData gd3 = new GridData(GridData.FILL_BOTH);
		g3.setLayoutData(gd3);
		GridLayout _layout3 = new GridLayout(3,false);
		_layout3.horizontalSpacing = 5;
		g3.setLayout(_layout3);
        g3.setText("3.设置desktop文件(非桌面应用不必需)");
      	
		table3 = new Table(g3, SWT.FULL_SELECTION | SWT.MULTI);
		table3.setHeaderVisible(false);
		table3.setLinesVisible(false);
		
		table3.addMouseListener(new MouseAdapter() {  
            public void mouseDown(MouseEvent e) {  
                if (e.button == 3) {  
                    Menu menu = new Menu(table3);  
                    table3.setMenu(menu);
                    MenuItem item = new MenuItem(menu, SWT.PUSH);  
                    item.setText("定位"); 
                    item.addListener(SWT.Selection, new Listener() {  
                        public void handleEvent(Event event) {  
                            TableItem item1 = (TableItem) table3  
                                    .getSelection()[0];  
                            Table parent = item1.getParent();  
                            if (parent != null) {  
                                
                                String pathSFolder = ExportSelectFolderWizardPage.sfoldernamePath_cache;
                				String pathCPK = pathSFolder +"/CPK/";
                				try {
									Runtime.getRuntime().exec("gnome-open " + pathCPK);
								} catch (IOException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								} 
                        }}});  
                    MenuItem item2 = new MenuItem(menu, SWT.PUSH);  
                    item2.setText("删除"); 
                    item2.addListener(SWT.Selection, new Listener() {  
                        public void handleEvent(Event event) {  
                            TableItem item1 = (TableItem) table3  
                                    .getSelection()[0];  
                            Table parent = item1.getParent();  
                            if (parent != null) {                                 
                                String pathSFolder = ExportSelectFolderWizardPage.sfoldernamePath_cache;
                				String pathCPK = pathSFolder +"/CPK/";
                				TableItem item = table3.getItem(table3.getSelectionIndex());
                				String fileName =  item.getText().trim();
                			    File myFile = new File(pathCPK + fileName);
                			    if(myFile.exists())
                			    {               
                				    myFile.delete();
                				    table3.remove(table3.getSelectionIndices());  
                                    TableItem it = new TableItem(table3, SWT.NONE);
                                    it.setText(new String[]{"", "", ""});
                                    it.setBackground(new Color(null, 230, 230, 230));
        
                			    }  
                        }
                            TableItem[] items =  table3.getItems();
                            boolean bFlag = false;
                            for(int i = 0; i < items.length; i++)
                            {
                            	 if(items.length != 0 && !items[i].getText().isEmpty())
                            	 {
                            		 bFlag = true;
                            		 break;
                            	 }
                                  else
                                  {
                                	  bFlag = false;
                                  }
                            } 
                            
                            if(bFlag)
                            	updateTips(tips3, true);
                            else
                            	updateTips(tips3, false);
                        } 
                    });  
                } 
            }  
        });    
		table3.addListener(SWT.MeasureItem, new Listener() {
            public void handleEvent(Event event) {
                event.height =28;
            }
        });
		
		// 创建表头的字符串数组  
	   newColumnTableColumn = new TableColumn(table3, SWT.NONE);
       newColumnTableColumn.setWidth(100);
       newColumnTableColumn.setText(Message.ExportSetInfoWizardPage_5);

       newColumnTableColumn_1 = new TableColumn(table3, SWT.NONE);
       newColumnTableColumn_1.setWidth(290);
       newColumnTableColumn_1.setText(Message.ExportSetInfoWizardPage_6);
      
       newColumnTableColumn_２ = new TableColumn(table3, SWT.NONE);
       newColumnTableColumn_２.setWidth(150);
       newColumnTableColumn_２.setText(Message.ExportSetInfoWizardPage_7);
		
        TableItem item3 = new TableItem(table3, SWT.NONE);
        item3.setText(new String[]{"", "", ""});
        item3.setBackground(new Color(null, 230, 230, 230));
        
        tips3 = new Label(g3, SWT.NULL);
        tips3.setImage(createdImage);
        tips3.setVisible(false);
        
        Button button3 = new Button(g3, SWT.NULL);
        button3.setText("设置");
        GridData _gd3 = new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1);
        _gd3.widthHint = 80;
        _gd3.heightHint = 35;
	    button3.setLayoutData(_gd3);
	    button3.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				String pathSFolder = ExportSelectFolderWizardPage.sfoldernamePath_cache;
				String pathCPK = pathSFolder +"/CPK/";
				 Utils.generalCPK(pathSFolder);
				//首先循环遍历其他文件夹目录下是否有.desktop文件
				//有就直接复制到CPK目录下，没有则创建。
				if(getFileList(pathSFolder) >= 1)
				{
					 MessageBox messageBox =   
		        			   new MessageBox(getShell(),   
		        			    SWT.OK|   
		        			    SWT.CANCEL|   
		        			    SWT.ICON_WARNING);  
		        			 messageBox.setMessage(Message.ExportSetInfoWizardPage_8 +pathSFolder+ Message.ExportSetInfoWizardPage_9 + count + Message.ExportSetInfoWizardPage_10 +pathCPK+ Message.ExportSetInfoWizardPage_11); 
					if(messageBox.open() == SWT.OK)
					{
						for (int i = 0; i < count - 1; i++) {
				            new TableItem(table3, SWT.NONE).setText("");
				        }
						setFileList(pathSFolder);
						updateTips(tips3, true);
					}	
					else
					{
						SetDesktop SD = new SetDesktop(Display.getCurrent().getActiveShell());
						SD.open();
						String file = pathCPK + SD.getFileName();	
						if(Utils.isExistFile(file) && SD.flag == 1)
						{
							//获取文件创建的时间
							File fs  =  new File(file); 
							long modify = fs.lastModified();
							FileInfo f = new FileInfo(SD.getFileName(), pathCPK, new  Timestamp(modify).toString());
							//list.add(f);
							 //设置表格数据  
							int n = table3.getItemCount();
							for(int i = 0; i < n; ++i)
							{
								 TableItem item = table3.getItem(i);
								 if(item.getText().trim().equals(SD.getFileName()) || item.getText().trim().isEmpty())
								 {
									 item.setText(f.toArray()); 
						             SD.flag = 0;
						             break;
								 }}}
							updateTips(tips3, true);
						}
				}else {
					SetDesktop SD = new SetDesktop(Display.getCurrent().getActiveShell());
					SD.open();
					String file = pathCPK + SD.getFileName();	
					if(Utils.isExistFile(file) && SD.flag == 1)
					{
						//获取文件创建的时间
						File fs  =  new File(file); 
						long modify = fs.lastModified();
						FileInfo f = new FileInfo(SD.getFileName(), pathCPK, new  Timestamp(modify).toString());
						//list.add(f);
						 //设置表格数据  
						int n = table3.getItemCount();
						for(int i = 0; i < n; ++i)
						{
							 TableItem item = table3.getItem(i);
							 if(item.getText().trim().equals(SD.getFileName()) || item.getText().trim().isEmpty())
							 {
								 item.setText(f.toArray()); 
					             SD.flag = 0;
					             break;
							 }
						}
						}
						updateTips(tips3, true);
				}
				count = 0;
			}});
        
        
        Group g4 = new Group(workArea, SWT.NULL);
		GridData gd4 = new GridData(GridData.FILL_BOTH);
		g4.setLayoutData(gd4);
		GridLayout _layout4 = new GridLayout(3,false);
		_layout4.horizontalSpacing = 5;
		g4.setLayout(_layout4);
        g4.setText("4. 设置filelist文件");
       
		table4 = new Table(g4, SWT.FULL_SELECTION | SWT.MULTI);
		table4.setHeaderVisible(false);
		table4.setLinesVisible(false);
		
		table4.addMouseListener(new MouseAdapter() {  
            public void mouseDown(MouseEvent e) {  
                if (e.button == 3) {  
                    Menu menu = new Menu(table4);  
                    table4.setMenu(menu);  
                    MenuItem item = new MenuItem(menu, SWT.PUSH);  
                    item.setText("定位"); 
                    item.addListener(SWT.Selection, new Listener() {  
                        public void handleEvent(Event event) {  
                            TableItem item1 = (TableItem) table4  
                                    .getSelection()[0];  
                            Table parent = item1.getParent();  
                            if (parent != null) {  
                                
                                String pathSFolder = ExportSelectFolderWizardPage.sfoldernamePath_cache;
                				String pathCPK = pathSFolder +"/CPK/";
                				try {
									Runtime.getRuntime().exec("gnome-open " + pathCPK);
								} catch (IOException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								} 
                        }}});  
                    MenuItem item2 = new MenuItem(menu, SWT.PUSH);  
                    item2.setText("删除"); 
                    item2.addListener(SWT.Selection, new Listener() {  
                        public void handleEvent(Event event) {  
                            TableItem item1 = (TableItem) table4  
                                    .getSelection()[0];  
                            Table parent = item1.getParent();  
                            if (parent != null) {                                 
                                String pathSFolder = ExportSelectFolderWizardPage.sfoldernamePath_cache;
                				String pathCPK = pathSFolder +"/CPK/";
                				TableItem item = table4.getItem(table4.getSelectionIndex());
                				String fileName =  item.getText().trim();
                			    File myFile = new File(pathCPK + fileName);
                			    if(myFile.exists())
                			    {  
                				    myFile.delete();
                				    table4.remove(table4.getSelectionIndices());  
                                    TableItem it = new TableItem(table4, SWT.NONE);
                                    it.setText(new String[]{"", "", ""});
                                    it.setBackground(new Color(null, 230, 230, 230));
                			    	bFilelist = false;
              				    	updateTips(tips4, false);
            				    	setPageComplete(false);     
                			    }  
                        }}});  
                }  
            }  
        });   
		table4.addListener(SWT.MeasureItem, new Listener() {
            public void handleEvent(Event event) {
                event.height =28;
            }
        });
		
		// 创建表头的字符串数组  
	   newColumnTableColumn = new TableColumn(table4, SWT.NONE);
       newColumnTableColumn.setWidth(100);
       newColumnTableColumn.setText(Message.ExportSetInfoWizardPage_5);

       newColumnTableColumn_1 = new TableColumn(table4, SWT.NONE);
       newColumnTableColumn_1.setWidth(290);
       newColumnTableColumn_1.setText(Message.ExportSetInfoWizardPage_6);
      
       newColumnTableColumn_２ = new TableColumn(table4, SWT.NONE);
       newColumnTableColumn_２.setWidth(150);
       newColumnTableColumn_２.setText(Message.ExportSetInfoWizardPage_7);
		
       TableItem item4 = new TableItem(table4, SWT.NONE);
       item4.setText(new String[]{"", "", ""});
       item4.setBackground(new Color(null, 230, 230, 230));
       
       tips4 = new Label(g4, SWT.NULL);
       tips4.setImage(createdImage);
       tips4.setVisible(false);

       Button button4 = new Button(g4, SWT.NULL);
       button4.setText("设置");
       GridData _gd4 = new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1);
       _gd4.widthHint = 80;
       _gd4.heightHint = 35;
	   button4.setLayoutData(_gd4);
	   button4.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				String pathSFolder = ExportSelectFolderWizardPage.sfoldernamePath_cache;
				String pathCPK = pathSFolder +"/CPK/";
				try {
					 new GenerateFilelist(ExportSelectFolderWizardPage.sfoldernamePath_cache);
				} catch (IOException e1) {
					// TODO 自动生成的catch块
					e1.printStackTrace();
				}
				String file = pathCPK+ "filelist";	
				if(Utils.isExistFile(file) )
				{
					//获取文件创建的时间
					File fs  =  new File(file); 
					long modify = fs.lastModified();
					FileInfo f = new FileInfo("filelist", pathCPK, new  Timestamp(modify).toString());
					//list.add(f);
					 //设置表格数据  
					int n = table4.getItemCount();
					for(int i = 0; i < n; ++i)
					{
						 TableItem item = table4.getItem(i);
						 if(item.getText().trim().equals("filelist") || item.getText().trim().isEmpty())
						 {
							 item.setText(f.toArray()); 
				             break;
						 }
					} 
					bFilelist = true; 
					updateTips(tips4, true);
					setPageComplete(bXml && bFilelist && bInstall);
				}	
			}});
        
       	
	}
	
	public static int  getFileList(String strPath) {
		File dir = new File(strPath);
		File[] files = dir.listFiles(); // 该文件目录下文件全部放入数组
		if (files != null) {
		for (int i = 0; i < files.length; i++) {
		String fileName = files[i].getName();
		if (files[i].isDirectory()) { // 判断是文件还是文件夹
		getFileList(files[i].getAbsolutePath()); // 获取文件绝对路径
		} else if (fileName.endsWith("desktop")) { // 判断文件名是否以.desktop结尾
		String strFileName = files[i].getAbsolutePath();
		String newPath = ExportSelectFolderWizardPage.sfoldernamePath_cache + "/CPK/"+files[i].getName();
		if(!strFileName.equals(newPath))
			count ++;
		} else {
		continue;
		}}}
		return count;
	}
	
	private void updateTips(Label tips, boolean b) {
		if(tips != null)
			tips.setVisible(b);
	}
	
	public static void  setFileList(String strPath) {
		String cpkPath = ExportSelectFolderWizardPage.sfoldernamePath_cache + "/CPK/";
		File dir = new File(strPath);
		File[] files = dir.listFiles(); // 该文件目录下文件全部放入数组
		if (files != null) {
		for (int i = 0; i < files.length; i++) {
		String fileName = files[i].getName();
		if (files[i].isDirectory()) { // 判断是文件还是文件夹
		setFileList(files[i].getAbsolutePath()); // 获取文件绝对路径
		} else if (fileName.endsWith("desktop")) { // 判断文件名是否以.desktop结尾
		String strFileName = files[i].getAbsolutePath();
		String newPath =cpkPath+files[i].getName();
		if(!strFileName.equals(newPath))
		{
	        Utils.copyFile(strFileName, newPath);
			//获取文件创建的时间
			long modify = files[i].lastModified();
			FileInfo fs = new FileInfo(files[i].getName(), cpkPath, new  Timestamp(modify).toString());
			//list.add(fs);
			 //设置表格数据  
			int n = table3.getItemCount();
			for(int j = 0; j < n; ++j)
			{
				 TableItem item = table3.getItem(j);
				 if(item.getText().trim().equals(files[i].getName()) || item.getText().trim().isEmpty())
				 {
					 item.setText(fs.toArray()); 
		             break;
				 }
			}   
		}
		} else {
		continue;
		}}}
	}
}
